﻿import QtQuick 2.0
import QtQuick 2.6
import QtQuick.Controls 2.3

Item {
    height: 800
    width: 400
    Rectangle{
        id:left
        color: Qt.rgba(Math.random(255),Math.random(255),Math.random(255),1.0)
        width: 80
        anchors.left: parent.left
        anchors.top: parent.top
        height: parent.height
        anchors.bottom: parent.bottom
    }

    Rectangle{
        id:top
        color: "#FFFFFF"//Qt.rgba(Math.random(255),Math.random(255),Math.random(255),1.0)
        width: parent.width-left.width
        anchors.top: parent.top
        anchors.right: parent.right
        anchors.left: left.right
        height: 40
        EMSearchBox{
            id:searchId
            anchors.fill: parent
            anchors.margins: 5
            onSignalTextFiledFocus: {
                showResultView(isFocus)
            }
            onSignalTextChanged: {
                if(!searchView.visible){
                    showResultView(true)
                }
                searchView.setText(text);
            }
        }
    }
    Rectangle{
        id:midRect
        color: Qt.rgba(Math.random(255),Math.random(255),Math.random(255),1.0)
        width: parent.width-left.width
        anchors.right: parent.right
        anchors.left: left.right
        anchors.bottom: parent.bottom
        anchors.top: top.bottom
        TextField {
            id: control
            placeholderText: qsTr("凉生 我们可不可以不忧伤")
            anchors.centerIn: parent
            height: 30
            color: "#333333"
            padding: 2
            leftPadding: 15
            rightPadding:15
            bottomPadding: 5
            selectByMouse: true
            selectionColor: "#0086F1"
            selectedTextColor: "#FFFFFF"
            background: Rectangle {
                implicitWidth: 200
                implicitHeight: 40
                color: "#F4F4F4"
                radius: 20
            }
        }
    }
    ListModel{
        id:copyModel
        Component.onCompleted: {
            copyModel.append({name:"重命名"})
            copyModel.append({name:"删除"})
            copyModel.append({name:"拷贝"})
            copyModel.append({name:"粘贴"})
            copyModel.append({name:"剪切"})
        }
    }
    QMLListView{
        id:searchView
        anchors.top: top.bottom
        width: searchId.width
        height: { (myModel == null)?1:(myModel.count*itemHeight+30)}
        x:searchId.x+left.width
        visible: false
        onSignalClickedItem: {
            searchId.updateFocus(false)
            showResultView(false);
        }
    }

    function showResultView(focus){
        if(searchView.myModel == null ){
            searchView.myModel = copyModel;
        }
        console.log("===============1==========",focus);
        if(searchView.visible == focus)return;
        console.log("===============2==========",focus);
        searchView.height = focus?(searchView.myModel.count*searchView.itemHeight+30):1;
        searchView.visible = focus;
        searchView.z = focus?10:0
    }
}
